home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Updates / General / TCL⁄C 1.1.2 Update Folder / TCL 1.1 Demos / NewClassDemo Folder / Demo sources / CResBrowser.c
Encoding:
C/C++ Source or Header  |  1991-09-25  |  5.8 KB  |  218 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CResBrowser.c
  3.  
  4.         A subclass of CDirector that manages a window containing a list
  5.         of resources.
  6.         
  7.     SUPERCLASS = CDirector
  8.     
  9.     Copyright © 1991 Symantec Corporation. All rights reserved.
  10.     
  11.  
  12.  ******************************************************************************/
  13.  
  14. #include "CResBrowser.h"
  15. #include "DemoCommands.h"
  16. #include "CResListPane.h"
  17. #include "CBrowseResDoc.h"
  18. #include "TBUtilities.h"
  19. #include "CDesktop.h"
  20. #include "CScrollPane.h"
  21. #include "CDecorator.h"
  22. #include "CWindow.h"
  23. #include "CArray.h"
  24.  
  25. #define    kResBrowseWind    1025        // 'WIND' resource ID 
  26.  
  27. extern CDesktop     *gDesktop;
  28. extern CDecorator    *gDecorator;
  29.  
  30. /******************************************************************************
  31.  IResBrowser
  32.  
  33.      Initialize CResBrowser. Creates a window to display the given list of
  34.      resources of the given type.
  35.      
  36. ******************************************************************************/
  37.  
  38. void CResBrowser::IResBrowser( CBrowseResDoc *aSupervisor, ResType aResType, 
  39.                         CArray *aResList)
  40. {
  41.     Str255    title;
  42.     Str31    suffix;
  43.     
  44.     resType = aResType;
  45.     itsResList = aResList;
  46.     itsResPane = NULL;
  47.     
  48.     CDirector::IDirector( aSupervisor);
  49.     
  50.         // set the title of the window to Filename - ResType,
  51.         // e.g. "Sample - DLOG"
  52.     
  53.     aSupervisor->GetName( title);
  54.     ConcatPStrings( title, "\p - xxxx");
  55.     BlockMove( &aResType, &title[ Length(title) - 3], sizeof(ResType));
  56.     
  57.         // create the window
  58.         
  59.     BuildWindow();
  60.     
  61.         // Set the window title
  62.         
  63.     itsWindow->SetTitle( title);
  64.     
  65.         // Position the window on screen and show it.
  66.         
  67.     gDecorator->StaggerWindow( itsWindow);
  68.     itsWindow->Select();
  69. }
  70.  
  71. /******************************************************************************
  72.  Dispose
  73.  
  74.      Dispose of the resource list when the window is closed.
  75.      
  76. ******************************************************************************/
  77.  
  78. void CResBrowser::Dispose( void)
  79. {
  80.     ForgetObject( itsResList);
  81.     inherited::Dispose();
  82. }
  83.  
  84. /******************************************************************************
  85.  DoCommand
  86.  
  87.      Respond to the cmdOpenResource command. It is sent when the user
  88.      double clicks on a resource name/ID.
  89.      
  90. ******************************************************************************/
  91.  
  92. void CResBrowser::DoCommand( long aCommand)
  93. {
  94.     tResourceInfo    resInfo;
  95.     Cell            selectedCell;
  96.     
  97.     switch( aCommand)
  98.     {
  99.         case cmdOpenResource:
  100.         
  101.                 // determine the selected cell.
  102.                 
  103.             selectedCell.h = selectedCell.v = 0;
  104.             if (itsResPane->GetSelect( kCurrentOrNext, &selectedCell))
  105.             {
  106.             
  107.                     // get the resource info for the selected cell
  108.                     // if it alreadt has a window, just show it,
  109.                     // otherwise create a new window for the resource
  110.                     
  111.                 itsResList->GetItem( &resInfo, selectedCell.v+1);
  112.                 if (resInfo.window)
  113.                     resInfo.window->GetWindow()->Select();
  114.                 else
  115.                 {
  116.                     
  117.                     resInfo.window = MakeResourceWindow( &resInfo);
  118.                     itsResList->SetItem( &resInfo, selectedCell.v + 1);
  119.                 }
  120.             }
  121.             break;
  122.             
  123.         default:
  124.             inherited::DoCommand( aCommand);
  125.             break;
  126.     }
  127. }
  128.  
  129. /******************************************************************************
  130.  BuildWindow
  131.  
  132.      Creates the window for display the resource list. CResListPane is a
  133.      subclass of CArrayPane that displays the scrolling list of resources.
  134.      
  135. ******************************************************************************/
  136.  
  137. void CResBrowser::BuildWindow( void)
  138. {
  139.     CScrollPane    *scrollPane;
  140.     
  141.         // First, create a window.
  142.     
  143.     itsWindow = new CWindow;
  144.     itsWindow->IWindow( kResBrowseWind, kNotFloating, gDesktop, this);
  145.     
  146.         // Next, add a scroll pane with a vertical scroll bar and
  147.         // a size box.
  148.         
  149.     scrollPane = new CScrollPane;
  150.     scrollPane->IScrollPane( itsWindow, this, 0, 0, 0, 0,
  151.                     sizELASTIC, sizELASTIC, kNoHScroll, kHasVScroll, kHasSizebox);
  152.     scrollPane->FitToEnclFrame( kDoHorizontal, kDoVertical);
  153.     
  154.         // Next, add the CResListPane
  155.  
  156.     itsResPane = new CResListPane;
  157.     itsResPane->IResListPane( scrollPane, this, 0, 0, 0, 0,
  158.                     sizELASTIC, sizELASTIC);
  159.     itsResPane->FitToEnclosure( kDoHorizontal, kDoVertical);
  160.     
  161.         // Install the resource list into the CResListPane,
  162.         // and set the double click command and selection flags
  163.     
  164.     itsResPane->SetArray( itsResList, FALSE);
  165.     itsResPane->SetDblClickCmd( cmdOpenResource);
  166.     itsResPane->SetSelectionFlags( selOnlyOne);
  167.     
  168.         // Connect the panorama to the scroll pane.
  169.  
  170.     scrollPane->InstallPanorama( itsResPane);
  171.     
  172.     itsGopher = itsResPane;
  173. }
  174.  
  175. /******************************************************************************
  176.  MakeResourceWindow
  177.  
  178.      Called when the user double clicks on a resource in the list. Subclasses
  179.      must override to display a particular resource type. CDLOGBrowser
  180.      overrides this method to display a DLOG window. This method just beeps.
  181. ******************************************************************************/
  182.  
  183. CDirector *CResBrowser::MakeResourceWindow( tResourceInfo *aResource)
  184. {
  185.     SysBeep( 3);
  186. }
  187.  
  188. /******************************************************************************
  189.  RemoveDirector {OVERRIDE}
  190.  
  191.      RemoveDirector is called when a subordinate director is being closed.
  192.      Since we store a reference to the subordinate director associated with
  193.      a resource in itsResList, we must be sure to clear that reference when
  194.      the subordinate director is closed.
  195. ******************************************************************************/
  196.  
  197.     static int FindResDirector( CDirector *resDirector, tResourceInfo *resInfo)
  198.     {
  199.         if (resInfo->window == resDirector)
  200.         {
  201.             resInfo->window = NULL;
  202.             return 0;
  203.         }
  204.         return 1;
  205.     }
  206.  
  207. void CResBrowser::RemoveDirector( CDirector *aDirector)
  208. {
  209.         // Search the resource list to find the reference to
  210.         // this director. The search routine clears the
  211.         // reference as soon as it is found.
  212.         
  213.     if (itsResList)
  214.         itsResList->Search( aDirector, (CompareFunc) FindResDirector);
  215.     
  216.     inherited::RemoveDirector( aDirector);
  217. }
  218.